Repository navigation
fix(167): file list name sort should use natural order (not character… - #201
Open
Mcchen1008 wants to merge 1 commit into
Open
Mcchen1008 wants to merge 1 commit into
Mcchen1008 wants to merge 1 commit into
Conversation
Open
4 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary / 摘要
file1, file10, file2, file20),而官方 Go 版 OpenList 出来的是自然数序(file1, file2, file3, file10, file11, file20),导致从 Go 版切到 Worker 版后排序看起来"乱了"。internal/model/config.go→model.SortFiles(orderBy="name"),发现它用的是github.com/maruel/natural.Compare(经典自然序),TS 端则是在src/backend/internal/driver/sort.ts里用了String(a.name).localeCompare(String(b.name)),导致排序行为不一致。 我以maruel/natural的行为为唯一事实来源,port 了对应的自然序比较器compareNames并只改了一个调用点。所有名(name/filename/file)排序口味的共享排序都会生效。Implementation changes / 实现改动
src/backend/internal/driver/sort.tscompareNames(a, b):开源实现 CommonPrefix(遇到数字停止)+leadingDigits+ 数值比较 + 前导零处理,语义与maruel/natural.Compare完全一致。sortFileItems的name分支从localeCompare改为compareNames;size/time/modified分支不受影响,且仍保持"文件夹优先"约定。src/backend/internal/driver/sort.test.ts(新增):13 个 Tests,覆盖file1/10/2/20/3/11、纯数字、含点文件名、前导零、大小写(ASCII 码位序,和 Gostrings.Compare一致)、中西文混合、空串、文件夹优先、倒序、size/modified不变、非破坏性等。maruel/natural.Compare82,000 对随机字符串的 cross-check(0 差异,见zz_crosscheck思路),不保留临时验证文件,避免 .test 污染。User-visible behavior / 用户可感知的行为变化
/api/fs/list等入口)按名称排序时,file1.txt, file2.txt, file3.txt, file10.txt顺序显示;之前file10,file20会排在file2,file3前面。sortFileItems(..., "name", ...)的驱动列表(webdav/onedrive/...)都受这个自然序影响;asc/desc与文件夹优先逻辑不变。localeCompare)未改动 — 只有列表页冲击。Related Issues / 关联 Issue
Closes #167Testing / 测试
pnpm run test:drivers— 239 pass(含新增的sort.test.ts)pnpm run test:pkg— 33 passpnpm run test:store— 15 passpnpm run test:model— 39 passpnpm run test:regress— 71/71 passpnpm run test:server— 238/239 pass,唯一失败storage_update_guangyapan(在 clean stash 基线上复现,与排序修改无关,pre-existing)tsc --noEmit无错,prettier --check通过file1, file2, file3, file10文件名的列表,该 PR 排序从 字符序 变成file1, file2, file3, file10;Go 版行为(通过maruel/natural)完全相同。Checklist / 检查清单
prettier格式化了变更代码(Vite 部分未改动)。Mcchen1008/OpenList-Worker:fix-natural-sort(主分支未改,需要 maintainers 合并 PR)。AI Disclosure / AI 使用声明
使用范围:代码生成(
compareNames自然序 port)+ 测试生成 + 文档撰写。zz_crosscheck对比验证思路)。github.com/maruel/natural/native,所有逻辑与单元测试都可复述)。